/**
 * Copyright (C) T-Systems International, 2013-2014
 *
 * The copyright of the computer program herein is the property of
 * T-Systems International. The program may be used and/or copied
 * only with the written permission of T-Systems International or in
 * accordance with the terms and conditions stipulated in the
 * agreement/contract under which the program has been supplied.
 *
 * $Author$
 * $Date$
 * $Rev$
 */
package com.tsystems.migdb.batch;

import com.tsystems.migdb.batch.validator.FieldValidator;
import lombok.AllArgsConstructor;
import org.springframework.batch.item.ItemProcessor;

import java.io.IOException;

@AllArgsConstructor
public class PersonItemProcessor implements ItemProcessor<Person, Person> {

    private volatile int count = 0;

    private FieldValidator fieldValidator;

    @Override
    public Person process(Person person) throws Exception {
        if(count == 2) {
            //throw new IOException();
            fieldValidator.validate(person);
        }
        else {
            count++;
        }
        return new Person(person.getFirstName().toUpperCase(), person.getLastName().toUpperCase());
    }

}